package com.gitee.wsl.compose.chart.xy.bar.stack

import androidx.compose.ui.graphics.Color
import com.gitee.wsl.compose.chart.xy.bar.Bar
import com.gitee.wsl.compose.chart.xy.bar.BarComposable
import com.gitee.wsl.compose.chart.xy.bar.solidBar

/**
 * Receiver scope used by [StackedVerticalBarPlot].
 */
 interface StackedVerticalBarPlotScope<X> {
    /**
     * Starts a new series of bars to be plotted, with a [defaultBar] to use for rendering all
     * bars in this series.
     */
     fun series(
        defaultBar: BarComposable = Bar.solidBar(Color.Blue),
        content: StackedVerticalBarPlotSeriesScope<X>.() -> Unit
    )
}

internal class StackedVerticalBarPlotScopeImpl<X> : StackedVerticalBarPlotScope<X> {
    val series: MutableList<StackedVerticalBarPlotSeriesScopeImpl<X>> = mutableListOf()
    override fun series(
        defaultBar: BarComposable,
        content: StackedVerticalBarPlotSeriesScope<X>.() -> Unit
    ) {
        val scope = StackedVerticalBarPlotSeriesScopeImpl<X>(defaultBar)
        series.add(scope)
        scope.content()
    }
}